package com.bwie.redkids.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.graphics.Paint;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bwie.redkids.R;
import com.bwie.redkids.bean.SearchFragemntBean.SearchProdictList;
import com.lidroid.xutils.BitmapUtils;

public class SearchFragmentAdapter extends BaseAdapter {

	private Context context;
	private ArrayList<SearchProdictList> arrayList;

	public SearchFragmentAdapter(Context context,
			ArrayList<SearchProdictList> arrayList) {
		this.context = context;
		this.arrayList = arrayList;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return arrayList.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return arrayList.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder = null;
		if (convertView == null) {
			convertView = View
					.inflate(context, R.layout.search_list_item, null);
			holder = new ViewHolder();
			holder.search_img = (ImageView) convertView
					.findViewById(R.id.search_img);
			holder.search_title = (TextView) convertView
					.findViewById(R.id.search_title);
			holder.search_old_price = (TextView) convertView
					.findViewById(R.id.search_old_price);
			holder.search_price = (TextView) convertView
					.findViewById(R.id.search_price);
			holder.search_smark = (TextView) convertView
					.findViewById(R.id.search_smark);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		BitmapUtils bitmapUtils = new BitmapUtils(context);
		bitmapUtils
				.display(holder.search_img, arrayList.get(position).getPic());
		holder.search_title.setText(arrayList.get(position).getName());
		holder.search_old_price.setText(""
				+ arrayList.get(position).getMarketprice());
		holder.search_old_price.getPaint()
				.setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
		holder.search_price.setText("" + arrayList.get(position).getPrice());
		holder.search_smark.setText("已有"
				+ arrayList.get(position).getComment_count() + "人评价");
		return convertView;
	}

	class ViewHolder {
		ImageView search_img;
		TextView search_title;
		TextView search_old_price;
		TextView search_price;
		TextView search_smark;
	}
}
